package com.common.baseconstant;

/**
 * function
 * Created by lhlong on 2016/12/6.
 */
public class Convert {

    public String upperCaseToPoJoName(String alphabet){
        StringBuffer sb = new StringBuffer("");
        char [] pojoName = alphabet.toCharArray();
        int index = 0;
        for (char albet:pojoName) {
            index++;
            if(index == 1&&isAlphabet(albet)){
                //首字母大写
                sb.append(Character.toUpperCase(albet));
            }
            else if (isAlphabet(albet)){
                sb.append(albet);
            }
        }
        return sb.toString();
    }

    /**
     *
     * @param alphabet
     * @return
     */
    public String lowerCaseToPoJoName(String alphabet){
        StringBuffer sb = new StringBuffer("");
        char [] pojoName = alphabet.toCharArray();
        int index = 0;
        for (char albet:pojoName) {
            index++;
            if(index == 1&&isAlphabet(albet)){
                //首字母大写
                sb.append(albet);
            }
            else if (isAlphabet(albet)){
                sb.append(Character.toLowerCase(albet));
            }
        }
        return sb.toString();
    }

    /**
     * 判断是否为字母
     * @param cr
     * @return
     */
    public Boolean isAlphabet(char cr){
        if ((cr <= 'z' && cr >= 'a') || (cr >= 'A' && cr<='Z')){
            return true;
        }
        return false;
    }

    public String convertToJavaType(String type){
        switch (type){
            case "INTEGER":return "java.lang.Integer";
            case "INT":return "java.lang.Integer";
            case "TINYINT":return "java.lang.Boolean";
            case "UNKNOWN":return "java.lang.String";
            case "SMALLINT": return "java.lang.Integer";
            case "MEDIUMINT":return "java.lang.Integer";
            case "BIGINT":return "java.lang.Long";

            case "DOUBLE": return "java.lang.Double";
            case "FLOAT":return "java.lang.Float";
            case "CHAR":return "java.lang.String";
            case "VARCHAR": return "java.lang.String";
            case "DATE":return "java.util.Date";
            case "TIME":return "java.sql.Time";

            case "YEAR": return "java.util.Date";
            case "TIMESTAMP":return "java.sql.Timestamp";
            case "DATETIME":return "java.util.Date";
            case "TEXT": return "java.lang.String";
            case "BIGDECIMAL":return "java.lang.Float";
            case "DECIMAL":return "java.lang.Float";

            default: break;
        }
        return "unknown";
    }
}
